#include <iostream>
using std::cout;
using std::endl;

class Point
{
public:
    /* Point() */
    /* : _ix(0) */
    /* , _iy(0) */
    /* { */
    /*     cout << "Point()" << endl; */
    /* } */

    Point(int x = 0,int y = 1)
    : _ix(x)
    , _iy(y)
    {
        cout << "Point(int,int)" << endl;
    }

    ~Point(){
        cout << "~Point()" << endl;
    }

    Point(const Point & rhs)
    : _ix(rhs._ix)
    , _iy(rhs._iy)
    {
        /* cout << "拷贝构造" << endl; */
    }

    Point & operator=(const Point & rhs){
        /* cout << "赋值运算符函数" << endl; */
        _ix = rhs._ix;
        _iy = rhs._iy;
        return *this;
    }

    void print(){
        cout << "(" << _ix
            << "," << _iy
            << ")";
    }
private:
    int _ix;
    int _iy;
};

class Line
{
public:
    Line(int x1,int y1,int x2,int y2)
    //Line的构造函数的初始化列表中需要显式调用Point
    //的构造完成对象成员的初始化
    //如果没有显式调用，编译器会自动调用Point的
    //无参构造或者所有参数都有默认值的有参构造
    //
    : _pt1(x1,y1)//调用了Point的构造函数
    , _pt2(x2,y2)
    {
        cout << "Line(int*4)" << endl;
    }

    ~Line(){
        cout << "~Line()" << endl;
    }

    void printLine(){
        _pt1.print();
        cout << "----->";
        _pt2.print();
        cout << endl;
    }


private:
    //Line类声明了Point类型的对象成员
    Point _pt1;
    Point _pt2;
};

void test0(){
    //从内存的角度来说
    //创建一个Line类对象，其内存布局中包含
    //两个Point类型的成员子对象
    Line ll(1,2,3,4);
    ll.printLine();
}

int main(void){
    test0();
    return 0;
}
